﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
using ExpressionPractices.ISqlServices;
using ExpressionPractices.Model;
using ExpressionPractices.Requests;

namespace ExpressionPractices.SqlServices
{
    /// <summary>
    /// homework数据库操作类
    /// </summary>
    public class HomeWorkServices : IHomeWorkServices
    {
        public bool AddUsers(List<T_User> users)
        {
            throw new NotImplementedException();
        }

        public bool DeleteUsers(UserRequest request = null)
        {
            //将参数利用表达式目录树，生成sql
            BinaryExpression expression;
            if (request != null)
            {
                ParameterExpression param = Expression.Parameter(typeof(T_User), "x");
                if (request.Id > 0)
                {
                    ConstantExpression paramId = Expression.Constant(request.Id, typeof(int));
                    Expression propertyExpression = Expression.Property(param, typeof(T_User).GetProperty("Id"));
                    expression = Expression.GreaterThan(propertyExpression, paramId);
                }
                if (!string.IsNullOrEmpty(request.Name))
                {
                    ConstantExpression paramname = Expression.Constant(request.Name, typeof(string));
                    Expression propertyExpression=Expression.Property(param,typeof(T_User).GetProperty("Name"));

                }
            }
            return true;
        }

        public List<T_User> GetUsers()
        {
            throw new NotImplementedException();
        }

        public bool UpdateUsers(List<T_User> users)
        {
            throw new NotImplementedException();
        }
    }
}
